// 引入utils请求函数
import request from '@/utils/goods';
import type {SpuResponeData,SpuTrademarkList,SpuBaseAttr,Record,ImageTypeArr,SkuArr} from './types';

enum API_URL {
  // 请求spu数据的地址
  GET_SPUDATA = '/admin/product/',
  // 请求SPU品牌的地址
  GET_TRADEMARKLIST = '/admin/product/baseTrademark/getTrademarkList',
  // 请求SPU销售属性的地址
  GET_BASEATTRLIST = '/admin/product/spuSaleAttrList/',
  // 获取SPU全部属性
  GET_ALLSPUATTR = '/admin/product/baseSaleAttrList',
  // 请求照片的地址
  GET_IMGLIST = '/admin/product/spuImageList/',

  // 更新已有SPU
  UPDATE_SPU = '/admin/product/updateSpuInfo',
  // 添加SPU
  ADD_SPU = '/admin/product/saveSpuInfo',

  // 查看SKU列表
  SKU_LIST = '/admin/product/findBySpuId/',

  // 请求删除SPU的地址
  DELETE_SPU = '/admin/product/deleteSpu/',

  // 添加SKU的地址
  ADD_SKU = '/admin/product/saveSkuInfo'
}

// 获取spu数据的接口
export const reqSpuData = (page: number,limit: number,category3Id: number | string) => {
  return request.get<any, SpuResponeData>(API_URL.GET_SPUDATA +`/${page}/${limit}?category3Id=${category3Id}`)};
// 获取SPU品牌的接口
export const reqSpuTrademarkList = () => {
  return request.get<any, SpuTrademarkList>(API_URL.GET_TRADEMARKLIST)
};
// 获取SPU销售属性的接口
export const reqSpuBaseAttr = (spuId: number) => {
  return request.get<any, SpuBaseAttr>(API_URL.GET_BASEATTRLIST + spuId)
};
// 获取SPU照片的接口
export const reqSupImgList = (spuId: number) => {
  return request.get<any, ImageTypeArr>(API_URL.GET_IMGLIST + spuId)
};
// 获取全部销售属性的接口
export const reqAllSpuAttr = () => {
  return request.get<any, any>(API_URL.GET_ALLSPUATTR);
};
// 添加与更新SPU
export const reqAddOrUpdateSpu = (data: Record) => {
  if (data.id){
    return request.post(API_URL.UPDATE_SPU, data);
  } else {
    return request.post(API_URL.ADD_SPU, data);
  }
};
// 查看SKU列表
export const reqSkuList = (skuId:number)=>{
  return request.get<any,SkuArr>(API_URL.SKU_LIST+skuId)
}
// 删除SPU的接口
export const reqDeleteSpu = (spuId: number) => {
  return request.delete<any, any>(API_URL.DELETE_SPU + `${spuId}`)
};
// 添加SKU的接口
export const reqADDSku = (data:any)=>{
  return request.post(API_URL.ADD_SKU,data)
}